package test6;

import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;

public class main {
    public static void main(String[] args) throws IOException, IllegalAccessException {
        write(new Student("小A",23,'女',167.5,"睡觉"));
    };

    public static void write(Object obj) throws IOException, IllegalAccessException {
        BufferedWriter bos = new BufferedWriter(new FileWriter("Java_11_23\\src\\test6\\a.txt"));
        Class clazz = obj.getClass();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            bos.write(field.getName() + "=" + field.get(obj));
            bos.newLine();
        }
        bos.close();
    }
}
